/* 业务逻辑 */
(function() {
	Path.on(["/__basename__.html", "/"], function() {
		App.set("$Cache.current_page", 1);
		//获取指定页的商品
		coAjax.get(appConfig.goods.list_with_page_info, {
			bus_id: busInfo._id,
			num: 3,
			page: 0
		}, function(result) {
			var goods_list = result.result.goods;
			App.set("$Cache.main.goods_list", goods_list);
		}, function() {
			console.log(arguments);
		});
	});

	// 加载分类树
	coAjax.get(appConfig.bus_classify_tree, {
		bus_id: busInfo._id
	}, function(classify_tree) {
		console.log(classify_tree.result);
		if (classify_tree.result.length) {
			classify_tree.result.childs.forEach(function(classify, index) {
				coAjax.get(appConfig.bus_classify_all_child_goods_by_id + classify.classify._id, {
					bus_id: busInfo._id
				}, function(classify_info) {
					App.concat("$Cache.main.classify_list", [{
						_id: classify.classify._id,
						title: classify.classify.classify_name,
						contents: classify_info.result
					}]);
					App.set("$Cache.main.loading_tags_completed", true);
				});
			});
		} else {
			App.set("$Cache.main.loading_tags_completed", true);
		};
	});
	// 加载标签列表
	// coAjax.get(appConfig.bus.tags_detail, {
	// 	bus_id: busInfo._id
	// }, function(result) {
	// 	console.log(result.result);
	// 	result.result.forEach(function(tag, index) {
	// 		App.concat("$Cache.main.tags", [{
	// 			_id: tag._id,
	// 			tag_name: tag.tag_name,
	// 			detail_content: tag.detail_content.reverse() //倒序排列商品
	// 		}]);
	// 		App.set("$Cache.main.loading_tags_completed", true);
	// 	});
	// 	// App.set("$Cache.main.tags", result.result);
	// });

}());

/*交互*/
;